<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>dictionary_add</title>
		<link rel="shortcut icon" href="../images/my/favicon.ico" />
		<link rel="bookmark" href="../images/my/favicon.ico" />
		<link rel="stylesheet" href="../../../plugins/layui/css/layui.css" />
		<link rel="stylesheet" href="../../../css/admin/common.css" />
		<link rel="stylesheet" href="../../../css/admin/users/update_my_base_info.css" />
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row">
				<div class="layui-col-md12">
					<div class="layui-card layui-anim layui-anim-upbit">
						<div class="layui-card-header">修改信息
							<span class="btn_right">
								<button type="button" id="back" title="返回" class="layui-btn layui-btn-normal layui-btn-xs" onclick="javascript:window.history.back(-1);"><i class="layui-icon">&#xe65c;</i>返回上一页</button>
								<button type="button" id="refresh" title="刷新" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-refresh"></i></button>
							</span>
						</div>
						<div class="layui-card-body">
							<form class="layui-form" action="">
								<div class="layui-form-item layui-row">
									<input type="hidden" name="id" />
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">type：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="text" name="type" required lay-verify="required" autocomplete="off" placeholder="type" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">key：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="text" name="k" required lay-verify="required" placeholder="key" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs12">value：</label>
									<div class="layui-col-md10 layui-col-sm10 layui-col-xs12">
										<input type="text" name="v" required lay-verify="required" placeholder="value" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-row">
									<label class="my_layui-form-label layui-col-md1 layui-col-sm1 layui-col-xs1 layui-hide-xs">&nbsp;</label>
									<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo"></i><span>保存修改</span></button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="../../../plugins/layui/layui.js"></script>
		<script>
			layui.config({
				base: '../../../js/admin/' //静态资源所在路径
			}).extend({
				common: 'common' //公共模块
			}).use(['common'], function() {
				var common = layui.common,
					layer = common.layer,
					$ = common.$,
					form = common.form;
				var id = common.getUrlParam("id")
				initData(id);
				//表单监听提交
				form.on('submit(formDemo)', function(data) {
					var user_data = data.field;
					sessionStorage.removeItem(user_data.type);
					user_data=JSON.stringify(user_data)
					$.ajax({
						url: IP + '/api/blog-admin/dictionary',
						type: 'PUT',
						data: user_data,
						success: function(result, status, xhr) {
							layer.closeAll('loading');
							layer.msg(result.message, {
								icon: 1,
								time: 1000
							},function(){
								window.history.back(-1);
							});
						}
					});
					return false;
				});
				//初始化页面数据
				function initData(id) {
					//用户数据
					showUser(id);
				}
				function showUser(id) {
					$.ajax({
						url: IP + '/api/blog-admin/dictionary',
						type: 'GET',
						data:{
							id:id
						},
						success: function(result, status, xhr) {
							layer.closeAll('loading');
							$("input[name='id']").val(result.data[0].id)
							$("input[name='type']").val(result.data[0].type)
							$("input[name='k']").val(result.data[0].k)
							$("input[name='v']").val(result.data[0].v)
						}
					});
				}
				
			});
		</script>
	</body>

</html>